package com.example.xjy.zyfypt_407xjy.model;



import com.example.xjy.zyfypt_407xjy.bean.ProjectBean;
import com.example.xjy.zyfypt_407xjy.iface.ProjectListener;
import com.example.xjy.zyfypt_407xjy.iface.Projectiface;
import com.example.xjy.zyfypt_407xjy.service.ProjectService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;



public class ProjectModel implements Projectiface {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    public ProjectModel() {
        retrofit=new Retrofit.Builder().baseUrl(BASEURL).addConverterFactory(GsonConverterFactory.create()).build();

    }


    @Override
    public void getResultList(String mod, int page, String SessionID, final ProjectListener projectListener) {
        ProjectService tcaseService =retrofit.create(ProjectService.class);
        Call<List<ProjectBean>> call= tcaseService.getResult(mod,page,SessionID);
        call.enqueue(new Callback<List<ProjectBean>>() {
            @Override
            public void onResponse(Call<List<ProjectBean>> call, Response<List<ProjectBean>> response) {
                if (response.isSuccessful()&&  response!=null){
                    projectListener.onResponse(response.body());
                }
                else
                    projectListener.onFail("on response fail");
            }

            @Override
            public void onFailure(Call<List<ProjectBean>> call, Throwable t) {
                projectListener.onFail(t.toString());
            }
        });

    }
}
